home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / gridex / frmemplo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-01-02  |  21.4 KB  |  628 lines

  1. VERSION 5.00
  2. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "COMCTL32.OCX"
  3. Begin VB.Form frmEmployees 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Employees"
  6.    ClientHeight    =   5535
  7.    ClientLeft      =   1110
  8.    ClientTop       =   2160
  9.    ClientWidth     =   7230
  10.    BeginProperty Font 
  11.       Name            =   "Tahoma"
  12.       Size            =   8.25
  13.       Charset         =   0
  14.       Weight          =   400
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    Icon            =   "frmEmployees.frx":0000
  20.    LinkTopic       =   "Form1"
  21.    LockControls    =   -1  'True
  22.    MaxButton       =   0   'False
  23.    MinButton       =   0   'False
  24.    ScaleHeight     =   369
  25.    ScaleMode       =   3  'Pixel
  26.    ScaleWidth      =   482
  27.    StartUpPosition =   2  'CenterScreen
  28.    Begin VB.PictureBox picFrame 
  29.       BorderStyle     =   0  'None
  30.       Height          =   3570
  31.       Index           =   1
  32.       Left            =   165
  33.       ScaleHeight     =   238
  34.       ScaleMode       =   3  'Pixel
  35.       ScaleWidth      =   460
  36.       TabIndex        =   16
  37.       Top             =   1095
  38.       Width           =   6900
  39.       Begin VB.ComboBox cboReportsTo 
  40.          Height          =   315
  41.          Left            =   1455
  42.          Sorted          =   -1  'True
  43.          Style           =   2  'Dropdown List
  44.          TabIndex        =   3
  45.          Top             =   1737
  46.          Width           =   3570
  47.       End
  48.       Begin VB.TextBox txtField 
  49.          Height          =   345
  50.          Index           =   11
  51.          Left            =   1455
  52.          TabIndex        =   5
  53.          Top             =   2595
  54.          Width           =   1170
  55.       End
  56.       Begin VB.TextBox txtField 
  57.          Height          =   345
  58.          Index           =   1
  59.          Left            =   1455
  60.          TabIndex        =   0
  61.          Top             =   435
  62.          Width           =   2490
  63.       End
  64.       Begin VB.TextBox txtField 
  65.          Height          =   345
  66.          Index           =   2
  67.          Left            =   1455
  68.          TabIndex        =   1
  69.          Top             =   870
  70.          Width           =   2490
  71.       End
  72.       Begin VB.TextBox txtField 
  73.          Height          =   315
  74.          Index           =   3
  75.          Left            =   1455
  76.          TabIndex        =   2
  77.          Top             =   1323
  78.          Width           =   3570
  79.       End
  80.       Begin VB.TextBox txtField 
  81.          Height          =   345
  82.          Index           =   10
  83.          Left            =   1455
  84.          TabIndex        =   4
  85.          Top             =   2151
  86.          Width           =   1155
  87.       End
  88.       Begin VB.Label lblEmployeeID 
  89.          AutoSize        =   -1  'True
  90.          BeginProperty Font 
  91.             Name            =   "Tahoma"
  92.             Size            =   9.75
  93.             Charset         =   0
  94.             Weight          =   700
  95.             Underline       =   0   'False
  96.             Italic          =   0   'False
  97.             Strikethrough   =   0   'False
  98.          EndProperty
  99.          Height          =   240
  100.          Left            =   1470
  101.          TabIndex        =   28
  102.          Top             =   90
  103.          Width           =   60
  104.       End
  105.       Begin VB.Label lblField 
  106.          Alignment       =   1  'Right Justify
  107.          AutoSize        =   -1  'True
  108.          BackStyle       =   0  'Transparent
  109.          Caption         =   "Employee ID:"
  110.          Height          =   195
  111.          Index           =   0
  112.          Left            =   180
  113.          TabIndex        =   27
  114.          Top             =   113
  115.          Width           =   960
  116.       End
  117.       Begin VB.Label lblField 
  118.          AutoSize        =   -1  'True
  119.          Caption         =   "Reports To:"
  120.          Height          =   195
  121.          Index           =   13
  122.          Left            =   285
  123.          TabIndex        =   23
  124.          Top             =   1797
  125.          Width           =   855
  126.       End
  127.       Begin VB.Label lblField 
  128.          AutoSize        =   -1  'True
  129.          Caption         =   "Extension:"
  130.          Height          =   195
  131.          Index           =   12
  132.          Left            =   375
  133.          TabIndex        =   22
  134.          Top             =   2670
  135.          Width           =   765
  136.       End
  137.       Begin VB.Label lblField 
  138.          Alignment       =   1  'Right Justify
  139.          AutoSize        =   -1  'True
  140.          Caption         =   "Hire Date:"
  141.          Height          =   195
  142.          Index           =   11
  143.          Left            =   405
  144.          TabIndex        =   21
  145.          Top             =   2226
  146.          Width           =   735
  147.       End
  148.       Begin VB.Label lblField 
  149.          Alignment       =   1  'Right Justify
  150.          AutoSize        =   -1  'True
  151.          Caption         =   "First Name:"
  152.          Height          =   195
  153.          Index           =   1
  154.          Left            =   315
  155.          TabIndex        =   20
  156.          Top             =   510
  157.          Width           =   825
  158.       End
  159.       Begin VB.Label lblField 
  160.          Alignment       =   1  'Right Justify
  161.          AutoSize        =   -1  'True
  162.          Caption         =   "Last Name:"
  163.          Height          =   195
  164.          Index           =   3
  165.          Left            =   330
  166.          TabIndex        =   19
  167.          Top             =   954
  168.          Width           =   810
  169.       End
  170.       Begin VB.Label lblField 
  171.          AutoSize        =   -1  'True
  172.          Caption         =   "Title:"
  173.          Height          =   195
  174.          Index           =   2
  175.          Left            =   780
  176.          TabIndex        =   18
  177.          Top             =   1383
  178.          Width           =   360
  179.       End
  180.    End
  181.    Begin VB.PictureBox picFrame 
  182.       BorderStyle     =   0  'None
  183.       Height          =   3615
  184.       Index           =   2
  185.       Left            =   150
  186.       ScaleHeight     =   3615
  187.       ScaleWidth      =   6900
  188.       TabIndex        =   25
  189.       Top             =   1065
  190.       Visible         =   0   'False
  191.       Width           =   6900
  192.       Begin VB.ComboBox cboTitleOfCourtesy 
  193.          Height          =   315
  194.          ItemData        =   "frmEmployees.frx":014A
  195.          Left            =   4995
  196.          List            =   "frmEmployees.frx":015A
  197.          TabIndex        =   12
  198.          Top             =   1990
  199.          Width           =   1800
  200.       End
  201.       Begin VB.TextBox txtField 
  202.          Height          =   660
  203.          Index           =   12
  204.          Left            =   1170
  205.          MultiLine       =   -1  'True
  206.          ScrollBars      =   2  'Vertical
  207.          TabIndex        =   14
  208.          Top             =   2880
  209.          Width           =   4740
  210.       End
  211.       Begin VB.TextBox txtField 
  212.          Height          =   345
  213.          Index           =   9
  214.          Left            =   1155
  215.          TabIndex        =   13
  216.          Top             =   2430
  217.          Width           =   1200
  218.       End
  219.       Begin VB.TextBox txtField 
  220.          Height          =   345
  221.          Index           =   5
  222.          Left            =   1170
  223.          TabIndex        =   7
  224.          Top             =   1110
  225.          Width           =   2340
  226.       End
  227.       Begin VB.TextBox txtField 
  228.          Height          =   345
  229.          Index           =   7
  230.          Left            =   1155
  231.          TabIndex        =   9
  232.          Top             =   1560
  233.          Width           =   2340
  234.       End
  235.       Begin VB.TextBox txtField 
  236.          Height          =   345
  237.          Index           =   8
  238.          Left            =   1155
  239.          TabIndex        =   11
  240.          Top             =   1990
  241.          Width           =   2340
  242.       End
  243.       Begin VB.TextBox txtField 
  244.          Height          =   345
  245.          Index           =   6
  246.          Left            =   4995
  247.          TabIndex        =   8
  248.          Top             =   1110
  249.          Width           =   1800
  250.       End
  251.       Begin VB.ComboBox cboCountry 
  252.          Height          =   315
  253.          Left            =   4995
  254.          TabIndex        =   10
  255.          Top             =   1575
  256.          Width           =   1800
  257.       End
  258.       Begin VB.TextBox txtField 
  259.          Height          =   720
  260.          Index           =   4
  261.          Left            =   1155
  262.          MultiLine       =   -1  'True
  263.          TabIndex        =   6
  264.          Top             =   210
  265.          Width           =   4740
  266.       End
  267.       Begin VB.Label lblField 
  268.          Alignment       =   1  'Right Justify
  269.          AutoSize        =   -1  'True
  270.          Caption         =   "Notes:"
  271.          Height          =   195
  272.          Index           =   15
  273.          Left            =   630
  274.          TabIndex        =   37
  275.          Top             =   2985
  276.          Width           =   480
  277.       End
  278.       Begin VB.Label lblField 
  279.          AutoSize        =   -1  'True
  280.          Caption         =   "Title of Courtesy:"
  281.          Height          =   195
  282.          Index           =   14
  283.          Left            =   3660
  284.          TabIndex        =   36
  285.          Top             =   2085
  286.          Width           =   1260
  287.       End
  288.       Begin VB.Label lblField 
  289.          AutoSize        =   -1  'True
  290.          Caption         =   "Birth Date:"
  291.          Height          =   195
  292.          Index           =   10
  293.          Left            =   330
  294.          TabIndex        =   35
  295.          Top             =   2505
  296.          Width           =   780
  297.       End
  298.       Begin VB.Label lblField 
  299.          Alignment       =   1  'Right Justify
  300.          AutoSize        =   -1  'True
  301.          Caption         =   "City:"
  302.          Height          =   195
  303.          Index           =   5
  304.          Left            =   765
  305.          TabIndex        =   34
  306.          Top             =   1185
  307.          Width           =   345
  308.       End
  309.       Begin VB.Label lblField 
  310.          AutoSize        =   -1  'True
  311.          Caption         =   "Region:"
  312.          Height          =   195
  313.          Index           =   6
  314.          Left            =   4380
  315.          TabIndex        =   33
  316.          Top             =   1185
  317.          Width           =   555
  318.       End
  319.       Begin VB.Label lblField 
  320.          Alignment       =   1  'Right Justify
  321.          AutoSize        =   -1  'True
  322.          Caption         =   "Postal Code:"
  323.          Height          =   195
  324.          Index           =   7
  325.          Left            =   195
  326.          TabIndex        =   32
  327.          Top             =   1625
  328.          Width           =   915
  329.       End
  330.       Begin VB.Label lblField 
  331.          AutoSize        =   -1  'True
  332.          Caption         =   "Country:"
  333.          Height          =   195
  334.          Index           =   8
  335.          Left            =   4290
  336.          TabIndex        =   31
  337.          Top             =   1635
  338.          Width           =   645
  339.       End
  340.       Begin VB.Label lblField 
  341.          Alignment       =   1  'Right Justify
  342.          AutoSize        =   -1  'True
  343.          Caption         =   "Home Phone:"
  344.          Height          =   195
  345.          Index           =   9
  346.          Left            =   150
  347.          TabIndex        =   30
  348.          Top             =   2065
  349.          Width           =   960
  350.       End
  351.       Begin VB.Label lblField 
  352.          Alignment       =   1  'Right Justify
  353.          AutoSize        =   -1  'True
  354.          Caption         =   "Address:"
  355.          Height          =   195
  356.          Index           =   4
  357.          Left            =   465
  358.          TabIndex        =   29
  359.          Top             =   270
  360.          Width           =   645
  361.       End
  362.    End
  363.    Begin VB.CommandButton cmdCancel 
  364.       Cancel          =   -1  'True
  365.       Caption         =   "Cancel"
  366.       Height          =   360
  367.       Left            =   3960
  368.       TabIndex        =   17
  369.       Top             =   5085
  370.       Width           =   1200
  371.    End
  372.    Begin VB.CommandButton cmdOK 
  373.       Caption         =   "OK"
  374.       Default         =   -1  'True
  375.       Height          =   360
  376.       Left            =   2655
  377.       TabIndex        =   15
  378.       Top             =   5085
  379.       Width           =   1200
  380.    End
  381.    Begin ComctlLib.TabStrip tabEmployees 
  382.       Height          =   4140
  383.       Left            =   105
  384.       TabIndex        =   24
  385.       Top             =   645
  386.       Width           =   7050
  387.       _ExtentX        =   12435
  388.       _ExtentY        =   7303
  389.       _Version        =   327682
  390.       BeginProperty Tabs {0713E432-850A-101B-AFC0-4210102A8DA7} 
  391.          NumTabs         =   2
  392.          BeginProperty Tab1 {0713F341-850A-101B-AFC0-4210102A8DA7} 
  393.             Caption         =   "Company Info"
  394.             Object.Tag             =   ""
  395.             ImageVarType    =   2
  396.          EndProperty
  397.          BeginProperty Tab2 {0713F341-850A-101B-AFC0-4210102A8DA7} 
  398.             Caption         =   "Personal Info"
  399.             Object.Tag             =   ""
  400.             ImageVarType    =   2
  401.          EndProperty
  402.       EndProperty
  403.    End
  404.    Begin VB.Image Image1 
  405.       Height          =   480
  406.       Left            =   180
  407.       Picture         =   "frmEmployees.frx":0173
  408.       Top             =   30
  409.       Width           =   480
  410.    End
  411.    Begin VB.Line Line1 
  412.       BorderColor     =   &H80000014&
  413.       Index           =   1
  414.       X1              =   6
  415.       X2              =   476
  416.       Y1              =   330
  417.       Y2              =   330
  418.    End
  419.    Begin VB.Line Line1 
  420.       BorderColor     =   &H80000010&
  421.       Index           =   0
  422.       X1              =   6
  423.       X2              =   476
  424.       Y1              =   329
  425.       Y2              =   329
  426.    End
  427.    Begin VB.Label lblName 
  428.       Alignment       =   1  'Right Justify
  429.       BackColor       =   &H80000003&
  430.       Caption         =   "Employees "
  431.       BeginProperty Font 
  432.          Name            =   "Tahoma"
  433.          Size            =   18
  434.          Charset         =   0
  435.          Weight          =   700
  436.          Underline       =   0   'False
  437.          Italic          =   0   'False
  438.          Strikethrough   =   0   'False
  439.       EndProperty
  440.       ForeColor       =   &H8000000E&
  441.       Height          =   525
  442.       Left            =   -30
  443.       TabIndex        =   26
  444.       Top             =   0
  445.       Width           =   7275
  446.    End
  447. Attribute VB_Name = "frmEmployees"
  448. Attribute VB_GlobalNameSpace = False
  449. Attribute VB_Creatable = False
  450. Attribute VB_PredeclaredId = True
  451. Attribute VB_Exposed = False
  452. Option Explicit
  453. Dim m_db As Database
  454. Dim mrstEmployees As Recordset
  455. Dim mvarBookmark As Variant
  456. Dim mbIsNew As Boolean
  457. Public Key As String
  458. Private Const fldFirstName = 1
  459. Private Const fldLastName = 2
  460. Private Const fldTitle = 3
  461. Private Const fldAddress = 4
  462. Private Const fldCity = 5
  463. Private Const fldRegion = 6
  464. Private Const fldPostalCode = 7
  465. Private Const fldHomePhone = 8
  466. Private Const fldBirthDate = 9
  467. Private Const fldHireDate = 10
  468. Private Const fldExtension = 11
  469. Private Const fldNotes = 12
  470. Private Const fldReportsTo = 13
  471. Private Const fldCountry = 14
  472. Private Const fldTitleOfCourtesy = 15
  473. Dim m_DataChanged(1 To 15) As Boolean
  474. Public Sub EditRecord(db As Database, rs As Recordset)
  475. Dim rstCountry As Recordset
  476. Dim i As Long
  477. On Error Resume Next
  478.     Set m_db = db
  479.     mvarBookmark = rs.Bookmark
  480.     Set mrstEmployees = rs.Clone
  481.     cboReportsTo.Clear
  482.     cboReportsTo.AddItem ""
  483.     Do Until mrstEmployees.EOF
  484.         cboReportsTo.AddItem mrstEmployees![FirstName] & " " & mrstEmployees![LastName]
  485.         cboReportsTo.ItemData(cboReportsTo.NewIndex) = mrstEmployees![EmployeeID]
  486.         mrstEmployees.MoveNext
  487.     Loop
  488.     mrstEmployees.Bookmark = mvarBookmark
  489.     Set rstCountry = m_db.OpenRecordset("SELECT DISTINCT Employees.Country FROM Employees ORDER BY Employees.Country", dbOpenSnapshot)
  490.     cboCountry.Clear
  491.     cboCountry.AddItem ""
  492.     Do Until rstCountry.EOF
  493.         cboCountry.AddItem rstCountry![Country]
  494.         rstCountry.MoveNext
  495.     Loop
  496.     lblName = mrstEmployees![FirstName] & " " & mrstEmployees![LastName] & "   "
  497.     lblEmployeeID = mrstEmployees![EmployeeID]
  498.     txtField(fldFirstName).Text = mrstEmployees![FirstName]
  499.     txtField(fldLastName).Text = mrstEmployees![LastName]
  500.     txtField(fldTitle).Text = mrstEmployees![Title]
  501.     txtField(fldAddress).Text = mrstEmployees![Address]
  502.     txtField(fldCity).Text = mrstEmployees![City]
  503.     txtField(fldRegion).Text = mrstEmployees![Region]
  504.     txtField(fldPostalCode).Text = mrstEmployees![PostalCode]
  505.     txtField(fldHomePhone).Text = mrstEmployees![Phone]
  506.     txtField(fldBirthDate).Text = Format(mrstEmployees![BirthDate], "Medium Date")
  507.     txtField(fldHireDate).Text = Format(mrstEmployees![HireDate], "Medium Date")
  508.     txtField(fldExtension).Text = mrstEmployees![Extension]
  509.     txtField(fldNotes).Text = mrstEmployees![Notes]
  510.     cboCountry.Text = mrstEmployees![Country]
  511.     cboTitleOfCourtesy.Text = mrstEmployees![TitleOfCourtesy]
  512.     If IsNull(mrstEmployees![ReportsTo]) Then
  513.         cboReportsTo.ListIndex = 0
  514.     Else
  515.         For i = 1 To cboReportsTo.ListCount - 1
  516.             If cboReportsTo.ItemData(i) = mrstEmployees![ReportsTo] Then
  517.                 cboReportsTo.ListIndex = i
  518.                 Exit For
  519.             End If
  520.         Next
  521.     End If
  522.     Caption = "Employees - " & mrstEmployees![FirstName] & " " & mrstEmployees![LastName]
  523.     For i = 1 To UBound(m_DataChanged)
  524.         m_DataChanged(i) = False
  525.     Next
  526.     Me.Show
  527. End Sub
  528. Public Sub NewRecord(db As Database, rs As Recordset)
  529. Dim rstCountry As Recordset
  530. Dim i As Long
  531. On Error Resume Next
  532.     Set m_db = db
  533.     Set mrstEmployees = rs.Clone
  534.     mbIsNew = True
  535.     mvarBookmark = Null
  536.     cboReportsTo.Clear
  537.     cboReportsTo.AddItem ""
  538.     Do Until mrstEmployees.EOF
  539.         cboReportsTo.AddItem mrstEmployees![FirstName] & " " & mrstEmployees![LastName]
  540.         cboReportsTo.ItemData(cboReportsTo.NewIndex) = mrstEmployees![EmployeeID]
  541.         mrstEmployees.MoveNext
  542.     Loop
  543.     Set rstCountry = m_db.OpenRecordset("SELECT DISTINCT Employees.Country FROM Employees ORDER BY Employees.Country", dbOpenSnapshot)
  544.     cboCountry.Clear
  545.     cboCountry.AddItem ""
  546.     Do Until rstCountry.EOF
  547.         cboCountry.AddItem rstCountry![Country]
  548.         rstCountry.MoveNext
  549.     Loop
  550.     lblName = "New Employee  "
  551.     cboReportsTo.ListIndex = 0
  552.     Caption = "Employees - New Employee"
  553.     Me.Show
  554. End Sub
  555. Private Sub cboCountry_Click()
  556.     m_DataChanged(fldCountry) = True
  557. End Sub
  558. Private Sub cboCountry_Change()
  559.     m_DataChanged(fldCountry) = True
  560. End Sub
  561. Private Sub cboReportsTo_Click()
  562.     m_DataChanged(fldReportsTo) = True
  563. End Sub
  564. Private Sub cboTitleOfCourtesy_Click()
  565.     m_DataChanged(fldTitleOfCourtesy) = True
  566. End Sub
  567. Private Sub cboTitleOfCourtesy_Change()
  568.     m_DataChanged(fldTitleOfCourtesy) = True
  569. End Sub
  570. Private Sub cmdCancel_Click()
  571.     Unload Me
  572. End Sub
  573. Private Sub cmdOK_Click()
  574. On Error GoTo EH_cmdOK
  575. Dim bUpdate As Boolean
  576. Dim i As Integer
  577.     For i = 1 To UBound(m_DataChanged)
  578.         If m_DataChanged(i) Then bUpdate = True
  579.     Next
  580.     If bUpdate Then
  581.         If mbIsNew Then
  582.             mrstEmployees.AddNew
  583.         Else
  584.             mrstEmployees.Edit
  585.         End If
  586.         If m_DataChanged(fldFirstName) Then mrstEmployees![FirstName] = txtField(fldFirstName)
  587.         If m_DataChanged(fldLastName) Then mrstEmployees![LastName] = txtField(fldLastName)
  588.         If m_DataChanged(fldTitle) Then mrstEmployees![Title] = txtField(fldTitle)
  589.         If m_DataChanged(fldHireDate) Then mrstEmployees![HireDate] = TextToNull(txtField(fldHireDate))
  590.         If m_DataChanged(fldExtension) Then mrstEmployees![Extension] = txtField(fldExtension)
  591.         If m_DataChanged(fldAddress) Then mrstEmployees![Address] = txtField(fldAddress)
  592.         If m_DataChanged(fldCity) Then mrstEmployees![City] = txtField(fldCity)
  593.         If m_DataChanged(fldRegion) Then mrstEmployees![Region] = txtField(fldRegion)
  594.         If m_DataChanged(fldPostalCode) Then mrstEmployees![PostalCode] = txtField(fldPostalCode)
  595.         If m_DataChanged(fldHomePhone) Then mrstEmployees![HomePhone] = txtField(fldHomePhone)
  596.         If m_DataChanged(fldBirthDate) Then mrstEmployees![BirthDate] = TextToNull(txtField(fldBirthDate))
  597.         If m_DataChanged(fldNotes) Then mrstEmployees![Notes] = txtField(fldNotes)
  598.         If m_DataChanged(fldCountry) Then mrstEmployees![Country] = cboCountry.Text
  599.         If m_DataChanged(fldTitleOfCourtesy) Then mrstEmployees![TitleOfCourtesy] = cboTitleOfCourtesy.Text
  600.         If m_DataChanged(fldReportsTo) Then
  601.             If cboReportsTo.Text = "" Then
  602.                 mrstEmployees![ReportsTo] = Null
  603.             Else
  604.                 mrstEmployees![ReportsTo] = cboReportsTo.ItemData(cboReportsTo.ListIndex)
  605.             End If
  606.         End If
  607.         mrstEmployees.Update
  608.         Hide
  609.         frmMain.OnRecordUpdate CatalogEmployees, mvarBookmark
  610.     End If
  611.     Unload Me
  612.     Exit Sub
  613. EH_cmdOK:
  614.     MsgBox Err.Description
  615. End Sub
  616. Private Sub Form_Unload(Cancel As Integer)
  617.     frmMain.UnloadForm Key
  618. End Sub
  619. Private Sub TabEmployees_BeforeClick(Cancel As Integer)
  620.     picFrame(tabEmployees.SelectedItem.Index).Visible = False
  621. End Sub
  622. Private Sub tabEmployees_Click()
  623.     picFrame(tabEmployees.SelectedItem.Index).Visible = True
  624. End Sub
  625. Private Sub txtField_Change(Index As Integer)
  626.     m_DataChanged(Index) = True
  627. End Sub
  628.